package com.psm.common;

import java.util.List;

import org.apache.log4j.Logger;

import com.jfinal.plugin.activerecord.cache.EhCache;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.psm.controller.*;
import com.psm.model.*;


/**
 * API引导式配置
 * @author 广州朴石茗文化发展有限公司
 * @Email pushiming@sina.cn
 */
public class PsmConfig extends JFinalConfig {
	
	 private static Logger logger = Logger.getLogger(PsmConfig.class);

	/**
	 * 配置常量
	 */
	public void configConstant(Constants me) {
		logger.info("系统启动,开始配置系统参数...");
		// 加载少量必要配置，随后可用getProperty(...)获取值
		loadPropertyFile("a_little_config.txt");
		me.setDevMode(getPropertyToBoolean("devMode", false));
		//loadAccessToken();
//		me.setViewType(ViewType.JSP);
	}

	/**
	 * 配置路由
	 */
	public void configRoute(Routes me) {
		logger.info("开始配置路由...");
		me.add("/admin/msg",WXMsgController.class);
		me.add("/admin",IndexController.class,"index");
		me.add("/admin/index", IndexController.class);			
		me.add("/admin/login", LoginController.class,"login");			
		me.add("/admin/user", UserController.class);			
		me.add("/admin/department", DepartmentController.class);			
		me.add("/admin/role", RoleController.class);			
		me.add("/admin/File",FileController.class);
		me.add("/admin/pwd", PwdController.class);
		me.add("/admin/code", CodeController.class);
		me.add("/puzone/content",PzonecController.class);
		me.add("/admin/posts",PostsController.class);
		me.add("/admin/terms",TermsController.class);
	}

	/**
	 * 配置插件
	 */
	public void configPlugin(Plugins me) {
		logger.info("开始配置插件...");
		// 配置C3p0数据库连接池插件
		C3p0Plugin dsMysql = new C3p0Plugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password").trim());
		me.add(dsMysql);

		// 配置ActiveRecord插件
		ActiveRecordPlugin arpMysql = new ActiveRecordPlugin("mysql",dsMysql);
		arpMysql.setShowSql(true);
		me.add(arpMysql);
		arpMysql.setCache(new EhCache());
		arpMysql.addMapping("sys_user", SysUser.class);	
		arpMysql.addMapping("sys_pa_code", SysPaCode.class);	
		arpMysql.addMapping("sys_ref_role_resource", SysRefRoleResource.class);
		arpMysql.addMapping("sys_ref_user_role", SysRefUserRole.class);	
		arpMysql.addMapping("sys_role", SysRole.class);	
		arpMysql.addMapping("sys_department", SysDepartment.class);	
        arpMysql.addMapping("pu_posts", PuPosts.class);
        arpMysql.addMapping("pu_terms", PuTerm.class);

	}

	/**
	 * 配置全局拦截器
	 */
	public void configInterceptor(Interceptors me) {

	}

	/**
	 * 配置处理器
	 */
	public void configHandler(Handlers me) {

	}

	/**
	 * 建议使用 JFinal 手册推荐的方式启动项目
	 * 运行此 main 方法可以启动项目，此main方法可以放置在任意的Class类定义中，不一定要放于此
	 */
	public static void main(String[] args) {
		JFinal.start("WebRoot", 80, "/", 5);
	}
}
